package com.yoda.youdianda.controller;

import com.yoda.youdianda.common.R;
import com.yoda.youdianda.domain.SysUser;
import com.yoda.youdianda.dto.PageDto;
import com.yoda.youdianda.dto.SysUserDto;
import com.yoda.youdianda.dto.UserDto;
import com.yoda.youdianda.service.SystemUserService;
import com.yoda.youdianda.vo.SysUserVo;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@Slf4j
@RequestMapping("/sys_user")
@AllArgsConstructor
public class SysUserController {

    @Autowired
    private SystemUserService systemUserService;


    //分页查询
    @GetMapping("/list")
    public R<PageDto> list(@RequestParam("login_name") String loginName, String status, String phone, int page, int limit) {
        PageDto pageDto = systemUserService.getList(loginName, status, phone, page, limit);
        return R.success(pageDto);
    }

    //用户添加
    @PostMapping("add")
    public R<String> add(@RequestBody UserDto dto) {
        return systemUserService.add(dto);
    }

    //用户删除
    @GetMapping("/del")
    public R<String> del(String id) {

        return systemUserService.del(id);
    }


    //用户详情:数据回显
    @GetMapping("rowInfo")
    public R<SysUserVo> rowInfo(String id) {
        return systemUserService.row(id);
    }

    //用户修改
    @PostMapping("/update")
    public R<String> update(@RequestBody UserDto sysUser) {

        return systemUserService.udp(sysUser);
    }
}
